package com.example.mengchun;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.mengchun.vo.User_json;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Administrator on 2017/10/17 0017.
 */

public class Xingzuo_m extends Fragment{
    int tetetete[] = {R.id.xingzuo_id,
            R.id.xingzuo_time,R.id.aa1,
            R.id.shuxing,R.id.aa2,
            R.id.xingyunshu,R.id.aa3,
            R.id.shouhuxing,R.id.aa4,
            R.id.xinggefenxi,R.id.aa5,
            R.id.jinriyunshi};

    String json = "";
    int biaoshi[] = {R.drawable.chunv,R.drawable.jinniu,R.drawable.juxie,R.drawable.mojie,R.drawable.muyang
            ,R.drawable.sheshou,R.drawable.shizi,R.drawable.shuangyu,R.drawable.shuangzi,R.drawable.shuiping
            ,R.drawable.tianping,R.drawable.tianxie};
    int []beijin = {R.drawable.xingzuo0,R.drawable.xingzuo1
            ,R.drawable.xingzuo2,R.drawable.xingzuo3
            ,R.drawable.xingzuo4,R.drawable.xingzuo5
            ,R.drawable.xingzuo6,R.drawable.xingzuo7
            ,R.drawable.xingzuo8,R.drawable.xingzuo9
            ,R.drawable.xingzuo10,R.drawable.xingzuo11};
    int biaosh = 0;

    private List<User_json.Lis_list> lislist;
    private List<User_json.Gri_list> grilist;


    public Xingzuo_m(String json,int biaosh){
        this.json = json;
        this.biaosh = biaosh;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        final View view = getActivity().getLayoutInflater().inflate(R.layout.xingzuo,null);
        ImageView ima = (ImageView) view.findViewById(R.id.xingzuo_imege);

        ima.setImageResource(biaoshi[biaosh]);
        getActivity().findViewById(R.id.fraglayout).setBackgroundResource(beijin[biaosh]);
        if (biaosh == 2 || biaosh == 6 || biaosh == 8){
            for(int i= 0 ;i<=11;i++){
                TextView t = (TextView) view.findViewById(tetetete[i]);
                t.setTextColor(Color.parseColor("#000000"));
            }
        }


        Gson g = new Gson();
        User_json user = g.fromJson(json,User_json.class);
        TextView text1 = (TextView) view.findViewById(R.id.xingzuo_id);
        TextView text2 = (TextView) view.findViewById(R.id.xingzuo_time);
        TextView text3 = (TextView) view.findViewById(R.id.shuxing);
        TextView text4 = (TextView) view.findViewById(R.id.xingyunshu);
        TextView text5 = (TextView) view.findViewById(R.id.shouhuxing);
        TextView text6 = (TextView) view.findViewById(R.id.xinggefenxi);
        TextView text7 = (TextView) view.findViewById(R.id.jinriyunshi);

        text1.setText(user.getXingzuo_id());
        text2.setText(user.getXingzuo_time());
        text3.setText(user.getShuxing());
        text4.setText(user.getXingyunshu());
        text5.setText(user.getShouhuxing());
        text6.setText(user.getXinggefenxi());
        text7.setText(user.getJinriyunshi());

        lislist = user.getLis_list();
        grilist = user.getGri_list();
        GridView gridView = (GridView) view.findViewById(R.id.gri_m);
        gridView.setAdapter(new Badapter());
        ListView listView = (ListView) view.findViewById(R.id.lis_m);
        listView.setAdapter(new Adapter());




        return view;
    }
    class Badapter extends BaseAdapter{

        String tet1[] = {"健康指数","商谈指数","幸运颜色","幸运数字"};
        @Override
        public int getCount() {
            return grilist.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            User_json.Gri_list us = grilist.get(position);
            convertView = getActivity().getLayoutInflater().inflate(R.layout.gri_item,null);
            TextView t1 = (TextView) convertView.findViewById(R.id.tete1);
            TextView t2 = (TextView) convertView.findViewById(R.id.tete2);
            t1.setText(tet1[position]);
            t2.setText(us.getText2()+"");
            return convertView;
        }
    }
    class Adapter extends BaseAdapter{
        String tt1[] = {"爱情运势","事业学业","财富运势","健康运势"};
        @Override
        public int getCount() {
            return lislist.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            User_json.Lis_list as = lislist.get(position);
            convertView = getActivity().getLayoutInflater().inflate(R.layout.lis_item,null);
            TextView t1 = (TextView) convertView.findViewById(R.id.tex_m1);
            TextView t2 = (TextView) convertView.findViewById(R.id.tex_m2);
            t1.setText(tt1[position]);
            t2.setText(as.getTe2());
            return convertView;
        }
    }


}
